
package sr.codemg.controller;

import sr.codemg.config.JwtConfig;
import sr.codemg.entity.SrProject;
import sr.codemg.utils.Constants;
import sr.codemg.vm.Base;
import sr.codemg.vm.Tables;
import sr.codemg.vm.Selects;
import sr.codemg.service.SrProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 我的项目
 **/
@Slf4j
@RestController
@RequestMapping("/srproject")
public class SrProjectController {

    @Autowired
    SrProjectService srProjectService;

    @GetMapping("/{id}")
    public SrProject get(@PathVariable("id") String id) {
        return srProjectService.get(id);
    }

    @PutMapping
    public Tables list(@RequestBody Map<String, Object> params) {
        return srProjectService.findList(params);
    }

    @PostMapping
    public Base.Response post(@RequestBody SrProject entity, @CookieValue(Constants.Authorization) String token) {
        entity.setId(null);
        return srProjectService.add(entity, JwtConfig.getUserId(token));
    }

    @PutMapping("/edit")
    public Base.Response put(@RequestBody SrProject entity, @CookieValue(Constants.Authorization) String token) {
        return srProjectService.update(entity);
    }

    @DeleteMapping("/{id}")
    public Base.Response delete(@PathVariable("id") String id) {
        return srProjectService.delete(id);
    }

    @PostMapping("/select")
    public Selects.Response select(@RequestBody Selects.Request req, @CookieValue(Constants.Authorization) String token) {
        req.setP1(JwtConfig.getUserId(token));
        return srProjectService.select(req);
    }
}

